/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JEditorPane;
import javax.swing.JScrollPane;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;

public class Form extends javax.swing.JFrame implements ActionListener{

    /**
     * Creates new form Form
     */
    public Form() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        display = new javax.swing.JEditorPane();
        addressBar = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        MenuBar = new javax.swing.JMenuBar();
        File = new javax.swing.JMenu();
        OpenPage = new openCommand(display);
        SavePage = new javax.swing.JMenuItem();
        ClosePage = new exitCommand(display);
        Bookmark = new javax.swing.JMenu();
        AddBookmark = new javax.swing.JMenuItem();
        DeleteBookmark = new javax.swing.JMenuItem();
        ShowBookmarks = new javax.swing.JMenuItem();
        History = new javax.swing.JMenu();
        ShowHistory = new javax.swing.JMenuItem();
        DeleteHistory = new javax.swing.JMenuItem();
        goPage = new BrowsePage(display, addressBar);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        addressBar.setText("Enter an URL host...");
        
        

        File.setText("File");

        OpenPage.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.CTRL_MASK));
        OpenPage.setText("Open Page");
        OpenPage.addActionListener(this);
        
        File.add(OpenPage);

        SavePage.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
        SavePage.setText("Save Page");
        File.add(SavePage);

        ClosePage.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_D, java.awt.event.InputEvent.CTRL_MASK));
        ClosePage.setText("Close Page");
        ClosePage.addActionListener(this);

        File.add(ClosePage);

        MenuBar.add(File);

        Bookmark.setText("Bookmarks");

        AddBookmark.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_B, java.awt.event.InputEvent.CTRL_MASK));
        AddBookmark.setText("Add Bookmark");
        Bookmark.add(AddBookmark);

        DeleteBookmark.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_B, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        DeleteBookmark.setText("Delete Bookmark");
        Bookmark.add(DeleteBookmark);

        ShowBookmarks.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_B, java.awt.event.InputEvent.SHIFT_MASK));
        ShowBookmarks.setText("Show All Bookmarks");
        Bookmark.add(ShowBookmarks);

        MenuBar.add(Bookmark);

        History.setText("History");

        ShowHistory.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_H, java.awt.event.InputEvent.CTRL_MASK));
        ShowHistory.setText("Show History");
        History.add(ShowHistory);

        DeleteHistory.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_H, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        DeleteHistory.setText("Delete History");
        History.add(DeleteHistory);

        MenuBar.add(History);

        goPage.setText("GO TO PAGE");
        goPage.addActionListener(this);
        MenuBar.add(goPage);

        setJMenuBar(MenuBar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(display, javax.swing.GroupLayout.DEFAULT_SIZE, 427, Short.MAX_VALUE)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING)
            .addComponent(addressBar)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(addressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(display, javax.swing.GroupLayout.PREFERRED_SIZE, 242, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    // private void OpenPageActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_OpenPageActionPerformed
    //     // TODO add your handling code here:
    // }//GEN-LAST:event_OpenPageActionPerformed

    // private void ClosePageActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ClosePageActionPerformed
    //     // TODO add your handling code here:
    // }//GEN-LAST:event_ClosePageActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Form.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Form.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Form.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Form.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Form().setVisible(true);
            }
        });
    }

    public void actionPerformed ( ActionEvent press )
    {
    
        if(press.getSource()== OpenPage)
        {
            OpenPage.execute();
        }
        else
            if(press.getSource()== ClosePage)
            {
               ClosePage.execute();
            }
             else
                 if(press.getSource()==goPage)
                 {
                     goPage.execute();
                 }
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem AddBookmark;
    private javax.swing.JMenu Bookmark;
    private exitCommand ClosePage;
    private javax.swing.JMenuItem DeleteBookmark;
    private javax.swing.JMenuItem DeleteHistory;
    private javax.swing.JMenu File;
    private javax.swing.JMenu History;
    private javax.swing.JMenuBar MenuBar;
    private openCommand OpenPage;
    private javax.swing.JMenuItem SavePage;
    private javax.swing.JMenuItem ShowBookmarks;
    private javax.swing.JMenuItem ShowHistory;
    private javax.swing.JTextField addressBar;
    private javax.swing.JEditorPane display;
    private BrowsePage goPage;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables


}
